//
//  DXWBaseMineViewController.m
//  pandaTV
//
//  Created by 淡馨慰 on 16/10/8.
//  Copyright © 2016年 淡馨慰. All rights reserved.
//

#import "DXWBaseMineViewController.h"
#import "DXWMineGroupItem.h"
#import "DXWMineRowItem.h"
#import "DXWMineCell.h"

@interface DXWBaseMineViewController ()

@end

@implementation DXWBaseMineViewController

- (NSMutableArray *)groupArray
{
    if (_groupArray == nil) {
        _groupArray = [NSMutableArray array];
    }
    return _groupArray;
}
//子类继承时保持tableView的分组类型
- (instancetype)init
{
    return [super initWithStyle:UITableViewStyleGrouped];
}

#pragma mark -UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    //共有多少组
    return self.groupArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //每组有多少行
    DXWMineGroupItem *groupItem = self.groupArray[section];
    return groupItem.rowItemArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //创建cell
    DXWMineCell *cell = [DXWMineCell cellWithTableView:tableView style:UITableViewCellStyleDefault];
    //取出组模型
    DXWMineGroupItem *groupItem = self.groupArray[indexPath.section];
    //取出行模型
    DXWMineRowItem *rowItem = groupItem.rowItemArray[indexPath.row];
    cell.rowItem = rowItem;
    //调整cell分割线的长度
//    cell.separatorInset = UIEdgeInsetsMake(0, 5, 0, 15);

    return cell;
}
-(void)viewDidLayoutSubviews

{
    
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
    }
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        
        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
    }
    
}



-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
        
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
        
    }
    
}

@end
